#include "MDQPParser.hpp"
#include "mdqp.hpp"
#include "log.hpp"

bool MDQPParser::parse()
{
    PcapPaser &paser = this->pcap_parser;
    if (paser.open())
    {
        LOG("open file success\n");

        while (!paser.isEOF())
        {
            size_t tcp_data_len = 0;
            uint8_t *tcp = paser.getTCP("172.16.68.3", "172.18.33.1", &tcp_data_len);
            if (tcp && tcp_data_len > 0)
            {
                if (tcp_data_len == 12100)
                {
                    LOG("get tcp success\n");
                }
                TcpPacketHeader *tcp_header = (TcpPacketHeader *)tcp;
                this->put(tcp + tcp_header->header_length * 4, tcp_data_len);
            }
            else
            {
                // LOG("get tcp failed\n");
            }
        }
        m_mdqp_header = (MDQPHeader *)m_content.data();
        return true;
    }
    else
    {
        LOG("open file failed\n");
        return false;
    }
}
